package com.wyp.java8;

import java.util.ArrayList;
import java.util.Arrays;

import java.util.List;
import java.util.stream.Stream;

/**
 * 题目:请按照给出数据，找出同时满足
 *     偶数ID
 *     且年龄大于24
 *     且用户名转为大写
 *     且用户名字母倒排序
 *     最后只输出一个用户名字
 */
public class StreamDemo1 {
    public static void main(String[] args) {

        User u1=new User(11,"f",23);
        User u2=new User(12,"m",24);
        User u3=new User(13,"c",22);
        User u6=new User(13,"c",21);
        User u4=new User(14,"d",28);
        User u5=new User(16,"e",27);

        List<User> list = Arrays.asList(u1,u2,u3,u4,u5);
//
//        list.stream().filter(t ->{return t.getId()%2 == 0;})
//                .filter(t -> {return t.getAge() > 22;})
//                //.limit(2)
//                //.skip(1)
//                .distinct()
//                .map(m -> { return m.getName().toUpperCase();})
//                //.sorted((o1, o2) -> {return o2.})
//                .forEach(System.out::println);

 //       List<String> list = Arrays.asList("ff","aa","bb","cc","dd");

    //    Stream<Stream<Character>> stream = list.stream().map(StreamDemo1::filterCharacter);

//        stream.forEach((sm)->{
//            sm.forEach(System.out::println);
//        });
//        System.out.println("------------------------");

       // list.stream().flatMap(StreamDemo1::filterCharacter).forEach(System.out::println);
        list.stream()
                //.map(t -> {return t.getName().toUpperCase();})
                .sorted((e1,e2)->{
                    if (e1.getName().equals(e2.getName())){
                        return e1.getAge().compareTo(e2.getAge());
                    }else{
                        return e1.getName().compareTo(e2.getName());
                    }
                })
                .forEach(System.out::println);

    }

    public static Stream<Character> filterCharacter(String str){
        List<Character> list = new ArrayList<>();

        for (Character ch : str.toCharArray()){
            list.add(ch);
        }
        return list.stream();


    }
}

class User{
    private  Integer id;
    private String name;
    private Integer age;
    private Status status;

    public User() {
    }

    public User(Integer id, String name, Integer age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public User(Integer id, String name, Integer age, Status status) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.status = status;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", status=" + status +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (id != null ? !id.equals(user.id) : user.id != null) return false;
        if (name != null ? !name.equals(user.name) : user.name != null) return false;
        return age != null ? age.equals(user.age) : user.age == null;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (age != null ? age.hashCode() : 0);
        return result;
    }

    public enum Status{

        FREE,BUSY,VOCATION;
    }
}
